import {createStore} from 'vuex';
import request from "@/request/request";



export default createStore({

    state: {
        isLogin:false,
        homeData: [],
    },
    getters: {

    },
    mutations: {
        modifyLoginStatus: (state,isLogin) => {
            state.isLogin = isLogin;
        },
        modifyHomeData:(state,data) => {
            state.homeData = data;
        }
    },
    actions: {
        login:({commit},params)=>{
            request('/login',{
                method:'post',
                data:params
            }).then((res)=>{
                console.log(res)
                if(res.status === 200){
                    // localStorage
                    localStorage.setItem("loginData",`username:${res.data.username} password: ${res.data.password}`);
                    commit('modifyLoginStatus',true);
                }else{
                    commit('modifyLoginStatus',false);
                }
            })
        },
        getHomeData:({commit})=>{
            request('/home').then((res)=>{
                if(res.status === 200){
                    commit('modifyHomeData',res.data);
                }else{
                    commit('modifyHomeData',[]);
                }
            })
        }
    },
    modules: {

    },
})